/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package servercom;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Administrator
 */
public class ServerDAO {
    ArrayList<DatabaseDAO> _lstDatabase;
    
    //Methods
    public ServerDAO()
    {
        _lstDatabase = new ArrayList<DatabaseDAO>();
    }
    
    public Boolean CreateDatabase(String name)
    {
        try
        {
            for (int i = 0; i < _lstDatabase.size(); i++) {
                if(_lstDatabase.get(i)._dbName.equalsIgnoreCase(name))
                {
                    return false;
                }
            }
            DatabaseDAO dbtemp = new DatabaseDAO(name);
        }
        catch (Exception e)
        {
            return false;
        }

        return true;
    }
    
    //delete
    public boolean DeleteDatabase(String name)
    {
        try
        {
            for (int i = 0; i < _lstDatabase.size(); i++) {
                if(_lstDatabase.get(i)._dbName.equalsIgnoreCase(name))
                {
                    _lstDatabase.remove(i);
                    return true;
                }
            }
        }
        catch (Exception e)
        {
            return false;
        }

        return false;
    }
    
    //rename
    public boolean RenameDatabase(String oldname ,String newname )
    {
        try
        {
            if(oldname.equalsIgnoreCase(newname))
            {
                return true;
            }
            int indexold = -1;
            for (int i = 0; i < _lstDatabase.size(); i++) {
                if(_lstDatabase.get(i)._dbName.equalsIgnoreCase(oldname))
                {
                    indexold = i;
                }
                if(_lstDatabase.get(i)._dbName.equalsIgnoreCase(newname))
                {
                    return false;
                }
            }
            if(indexold != -1)
            {
                _lstDatabase.get(indexold)._dbName = newname;
            }
        }
        catch (Exception e)
        {
            return false;
        }

        return false;
    }
    
}
